package com.whl215.kit.grape.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.whl215.kit.adapter.GrapeQuickAdapter
import com.whl215.kit.adapter.GrapeViewHolder
import com.whl215.kit.grape.R
import com.whl215.kit.grape.databinding.ItemUserInfoBinding
import com.whl215.kit.grape.model.UserBean

/**
 * author： happiness
 * date： 2021/5/4
 * description：用户列表
 */
class UserAdapter : GrapeQuickAdapter<UserBean>() {

    override fun convert(holder: GrapeViewHolder, position: Int, item: UserBean) {
        val viewBinding:ItemUserInfoBinding =holder.getViewBinding()
        viewBinding.itemImgHeadPortrait.setImageResource(item.headPortrait)
        "年龄 : ${item.age}".also { viewBinding.itemTvAge.text = it }
        viewBinding.itemTvName.text =  item.name
        holder.setOnClickListener(viewBinding.itemTvName)
        holder.setOnClickListener(viewBinding.itemTvAge)
        holder.setOnClickListener(viewBinding.itemImgHeadPortrait)
//        holder.setImageResource(R.id.item_img_head_portrait, item.headPortrait)
//            .setText(R.id.item_tv_name, item.name)
//            .setText(R.id.item_tv_age, "年龄 : ${item.age}")
//            .setOnClickListener(R.id.item_img_head_portrait)
//            .setOnClickListener(R.id.item_tv_name)
//            .setOnClickListener(R.id.item_tv_age)
    }

    override fun getViewBinding(parent: ViewGroup): ViewBinding {
        return ItemUserInfoBinding.inflate(LayoutInflater.from(parent.context),parent,false)
    }

}